<?php
use yii\widgets\ActiveForm;
use yii\helpers\Html;
use common\components\widgets\Datetimepicker;
Datetimepicker::widget(['timepicker' => 'false','datepicker'=>'true','step'=>'5']);
?>
<div class="yx-praise-list-box yx-praise-box yx-radius2 zx-min-height yx-add-content-box" >
<?php $form = ActiveForm::begin(['enableAjaxValidation' => true,'enableClientValidation' => false,'options'=>['class'=>'form-validate']]); ?>
<table width="100%" class="table-form" >
    <tr>
        <th class="zx-goods-table"><?= $model->attributeLabels()['name']; ?></th>
        <td><?= $form->field($model, 'name', ['template' => '{input}{error}'])->textInput(['class' => 'input-text']) ?></td>
    </tr>
    <tr>
        <th class="zx-goods-table"><?= $model->attributeLabels()['type']; ?></th>
        <td style="display: inline-block;"><?= $form->field($model, 'type', ['template' => '{input}{error}{hint}'])->widget(\kartik\select2\Select2::className(),['data'=>['discount'=>'折扣券','full'=>'满减券','freight'=>'运费券'],'options' => ['placeholder' => '请选择']]) ?></td>
    </tr>

    <tr>
        <th class="zx-goods-table"><?= $model->attributeLabels()['amount']; ?></th>
        <td><?= $form->field($model, 'amount', ['template' => '{input}{hint}{error}'])->textInput([ 'class' => 'input-text'])->hint('如果是折扣券填写百分比（如9折就填写90）') ?></td>
    </tr>
    <tr>
        <th class="zx-goods-table"><?= $model->attributeLabels()['total']; ?></th>
        <td><?= $form->field($model, 'total', ['template' => '{input}{hint}{error}'])->textInput([ 'class' => 'input-text']); ?></td>
    </tr>
    <tr>
        <th class="zx-goods-table"><?= $model->attributeLabels()['quantity']; ?></th>
        <td><?= $form->field($model, 'quantity', ['template' => '{input}{hint}{error}'])->textInput([ 'class' => 'input-text']); ?></td>
    </tr>
    <tr>
        <th class="zx-goods-table"><?= $model->attributeLabels()['start_time']; ?></th>
        <td><?= $form->field($model, 'start_time', ['template' => '{input}{hint}{error}'])->textInput([ 'class' => 'datetimepicker form_datetime input-text']); ?></td>
    </tr>
    <tr>
        <th class="zx-goods-table"><?= $model->attributeLabels()['end_time']; ?></th>
        <td><?= $form->field($model, 'end_time', ['template' => '{input}{hint}{error}'])->textInput([ 'class' => 'datetimepicker form_datetime input-text']); ?></td>
    </tr>
    <tr>
        <th class="zx-goods-table"><?= $model->attributeLabels()['maturity_type']; ?></th>
        <td style="display: inline-block;"><?= $form->field($model, 'maturity_type', ['template' => '{input}{error}{hint}'])->widget(\kartik\select2\Select2::className(),['data'=>['W'=>'固定周','D'=>'固定天数'],'options' => ['placeholder' => '请选择']]) ?></td>
    </tr>
    <tr id="week" style="display: <?php if($model->maturity_type == 'W') echo 'table-row'; else echo 'none';?>">
        <th class="zx-goods-table"><?= $model->attributeLabels()['maturity_week']; ?></th>
        <td style="display: inline-block;"><?= $form->field($model, 'maturity_week', ['template' => '{input}{error}{hint}'])->widget(\kartik\select2\Select2::className(),['data'=>['1'=>'周一','2'=>'周二','3'=>'周三','4'=>'周四','5'=>'周五','6'=>'周六','7'=>'周天'],'options' => ['placeholder' => '请选择']]) ?></td>
        <td><?= $form->field($model, 'maturity_type', ['template' => '{input}{hint}{error}'])->dropDownList(['W'=>'固定周','D'=>'固定天数'],['prompt'=>'选择类型','class' => 'input-dropdownlist']); ?></td>
    </tr>
    <tr id="week" style="display: <?php if($model->maturity_type == 'W') echo 'table-row'; else echo 'none';?>">
        <th class="zx-goods-table"><?= $model->attributeLabels()['maturity_week']; ?></th>
        <td><?= $form->field($model, 'maturity_week', ['template' => '{input}{hint}{error}'])->dropDownList(['1'=>'周一','2'=>'周二','3'=>'周三','4'=>'周四','5'=>'周五','6'=>'周六','7'=>'周天'],['prompt'=>'选择星期','class' => 'input-dropdownlist']); ?></td>
    </tr>
    <tr id="day" style="display: <?php if($model->maturity_type == 'D') echo 'table-row'; else echo 'none';?>">
        <th class="zx-goods-table"><?= $model->attributeLabels()['maturity_day']; ?></th>
        <td><?= $form->field($model, 'maturity_day', ['template' => '{input}{hint}{error}'])->textInput(['class' => 'input-text']); ?></td>
    </tr>
    <tr style="display: none">
        <th class="zx-goods-table"><?= $model->attributeLabels()['platforms']; ?></th>
        <td><?= $form->field($model, 'platforms', ['template' => '{input}{hint}{error}'])->checkboxList(['pc'=>'pc端','wechat'=>'微信端','app'=>'app端'],[ 'class' => 'input-checkboxlist']); ?></td>
    </tr>
    <tr>
        <th class="zx-goods-table"><?= $model->attributeLabels()['description']; ?></th>
        <td style="padding-right: 20px;"><?= $form->field($model, 'description', ['template' => '{input}{error}{hint}'])->widget(\doumiaoduo\ueditor\Ueditor::className(), ['clientOptions'=>[
                'serverUrl'=>\common\components\helpers\Fun::url(['/uploader/action']),
                'toolbars'=>[['fullscreen', 'source', '|', 'undo', 'redo', '|','bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript','rowspacingtop', 'rowspacingbottom', 'lineheight', '|','justifyleft', 'justifycenter', 'justifyright', 'justifyjustify','simpleupload','removeformat']],
                'initialFrameWidth'=>'60%'
            ]]); ?></td>
    </tr>
</table>
    <div class="yx-submit-box" style="width: 100%">
        <?= \yii\helpers\Html::submitButton('提交', ['class' => "button yx-submit", 'id' => 'dosubmit']) ?>
    </div>
</div>

<?php \yii\widgets\ActiveForm::end(); ?>
<?php
$js = <<<JS

    $(document).on('change','#coupons-maturity_type',function(){
        var val = $(this).val();
        if(val == 'W'){
            $('#week').show();
            $('#day').hide();
        }else{
            $('#week').hide();
            $('#day').show();
        }
    });

    // var conditions=null;
    // var ids='';
    //
    // var id=$('.table-form').data('condition');
    // if(id!=''){
    //    $('#'+id).show();
    // }
    // conditions=$('#coupons-conditions input[type=radio]:checked').val();
    // $('#coupons-conditions input[type=radio]').change(function(){
    //     var val=$(this).val();
    //     conditions=val;
    //     $('.condition').hide();
    //     $('#'+val).show();
    // });

    // $('#dosubmit').click(function(){
    //     if(conditions!='all'){
    //          $('#'+conditions+ " input:checked").each(function() {
    //             (ids =='') ? ids = $(this).val() : ids += ',' + $(this).val();
    //          });
    //          if(ids.length==0){
    //             alert('请根据使用条件进行相关设置！');return false;
    //          }
    //     }
    //
    // })
JS;
$this->registerJS($js);
?>

